package main

import (
	"fmt"
)

type A struct{
	Name string 
	age int 
}
type B struct{
	Name string 
	age float64
}
type C struct {
	A 
	B //继承 匿名结构体
}
type D struct{
	a A //组合  有名
}

type Goods struct{
	Name string 
	Price float64
}
type Brand struct{
	Name string 
	Address string 
}
type TV struct{
	Goods 
	Brand //嵌入匿名结构体继承
}
type TV2 struct{
	*Goods 
	*Brand 
}

type Monster struct{
	Name string 
	Age int 
}
type E struct{
	Monster
	int //匿名类型字段 
	n int 
}
func main(){

	// var obj C 
	// //obj.Name="jack"
	// obj.A.Name="tom"

	// fmt.Println(obj)

	// var x D 
	// //x.a.Name="lucy"
	// x.Name="jack"

	// fmt.Println(x)


	tv1:=TV{Goods{"黑白",123.2},Brand{"彩虹","北京"}}
	tv2:=TV{
		Goods{
			Name:"彩色",
			Price:11.2,
		},
		Brand{
			Name:"夏普",
			Address:"上海",
		},
	}

	fmt.Println(tv1,tv2)

	tv3:=&TV2{&Goods{"液晶",12.2},&Brand{"松下","日本"}}
	tv4:=&TV2{
		&Goods{
			Name:"LED",
			Price:33.33,
		},
		&Brand{
			Name:"淘宝",
			Address:"浙江",
		},
	}

	fmt.Println(*tv3,*tv4)

	fmt.Println(*tv3.Goods,*tv3.Brand,*tv4.Goods,*tv4.Brand)

	fmt.Println(tv3.Goods.Name,tv4.Goods.Name)

	fmt.Println("******************")

	fmt.Println(tv3.Brand.Name,tv4.Brand.Name)

	e:=E{}
	e.Name="hulijing"
	e.Monster.Name="baba"
	e.Age=888
	e.int=20
	e.n=1000

	fmt.Println("e=",e)
}